#include<vector>
using namespace std;
class Solution {
public:
    void duplicateZeros(vector<int>& arr) {

        int cur=0;
        int dest = -1;
        for(;cur<arr.size();cur++)
        {
            if(arr[cur]!=0)
            {
                dest++;
            }
            else
            {
                dest+=2;
            }
            if(dest>=arr.size()-1)
            {
                break;
            }
        }
        //超过边界
        if(dest>arr.size()-1)
        {
            dest-=2;
            cur-=1;
            arr[arr.size()-1]=0;
        }
        while(cur>=0)
        {
            if(arr[cur]!=0)
            {
                arr[dest--]=arr[cur--];
            }
            else
            {
                arr[dest--]=arr[cur];
                arr[dest--]=arr[cur--];
            }
        }
    }
};